package com.reef.dao;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.reef.entity.Book;

public interface BookRepository extends JpaRepository<Book, Integer>,JpaSpecificationExecutor<Book>{
   /**
    * 修改数量和被借阅数量
    */
	@Transactional
	@Modifying
	@Query(value = "UPDATE book SET number=number-?1,lendnum=lendnum+?2 WHERE book_id=?3",nativeQuery = true)
	int updateByNumber(int number,int lendnum,int book_id);
	/**
	 * 修改图书数量
	 */
	@Transactional
	@Modifying
	@Query(value = "UPDATE book SET number = number+?1 where book_id=?2",nativeQuery = true)
	int updateByBookNumber(int number,int book_id);
}
